package com.genesis.yunnanji.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.genesis.yunnanji.R;
import com.genesis.yunnanji.bean.IndexBean;
import com.genesis.yunnanji.bean.NewsBean;
import com.genesis.yunnanji.config.GenesisApiConfig;
import com.genesis.yunnanji.fragment.News;
import com.genesis.yunnanji.utils.DateUtils;
import com.genesis.yunnanji.utils.GenesisUtils;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.callback.BitmapLoadCallBack;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2017/11/9.
 */

public class NewsAdapter extends BaseQuickAdapter<NewsBean, BaseViewHolder> {
    private Context context;
    private boolean isVideo = false;

    public NewsAdapter(Context context, @Nullable List<NewsBean> data) {
        super(R.layout.layout_news_item, data);
        this.context = context;
    }

    public NewsAdapter(Context context, @Nullable List<NewsBean> data, boolean isVideo) {
        super(R.layout.layout_news_item, data);
        this.context = context;
        this.isVideo = isVideo;
    }


    @Override
    protected void convert(BaseViewHolder helper, NewsBean item) {
        helper.setText(R.id.tv_newsitem_title, item.getTitle());
        helper.setText(R.id.tv_newsitem_readcount, "阅读  " + item.getView());
        helper.setText(R.id.tv_newsitem_date, DateUtils.getTimeOfMMDD(item.getAdd_time()));

        BitmapUtils bitmapUtils = new BitmapUtils(context);
        BitmapDisplayConfig displayConfig = new BitmapDisplayConfig();
        displayConfig.setLoadingDrawable(context.getResources().getDrawable(R.mipmap.default_left));
        displayConfig.setLoadFailedDrawable(context.getResources().getDrawable(R.mipmap.default_left));
        bitmapUtils.display((ImageView) helper.getView(R.id.iv_newsitem_icon), GenesisApiConfig.PIC_HOST + item.getCover_img(), displayConfig);
        if (TextUtils.isEmpty(item.getCover_img())) {
            helper.getView(R.id.rl_newsitem_icon).setVisibility(View.GONE);
        } else {
            helper.getView(R.id.rl_newsitem_icon).setVisibility(View.VISIBLE);
        }

        if (isVideo == true) {
            helper.getView(R.id.iv_newsitem_video).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.iv_newsitem_video).setVisibility(View.GONE);
        }
    }
}
